package Org.B3;

import org.assertj.core.api.Assertions;
import org.example.B3.Event;
import org.example.B3.State;

import org.example.B3.WorkOver;
import org.junit.jupiter.api.Test;

class WorkOvertest {
    @Test
    void when_firstQuote() {
        WorkOver workOver = new WorkOver();
        workOver.setCurrentChar('\"');
        workOver.fire(Event.quote);
        State state = workOver.getCurrentState();
        workOver.printCurrentState();
        Assertions.assertThat(state).isEqualTo(State.ReadString);
    }

    @Test
    void when_secondQuote() {
        WorkOver workOver = new WorkOver();
        workOver.setCurrentChar('\"'); //第一次遇到双引号
        workOver.fire(Event.quote);//进入ReadingString
        workOver.printCurrentState();
        workOver.setCurrentChar('\"'); //第二次遇到双引号
        workOver.fire(Event.quote);
        State state = workOver.getCurrentState();
        workOver.printCurrentState();
        Assertions.assertThat(state).isEqualTo(State.Output);
    }

    @Test
    void when_backslash() {
        WorkOver workOver = new WorkOver();
        workOver.setCurrentChar('\"'); //遇到双引号
        workOver.fire(Event.quote);
        workOver.setCurrentChar('\\'); //遇到反斜杠
        workOver.fire(Event.backslash);
        State state = workOver.getCurrentState();
        workOver.printCurrentState();
        Assertions.assertThat(state).isEqualTo(State.Transfering);
    }
}



